<?php

namespace app\admin\model\product;

use think\Model;


class Subject extends Model
{

    

    

    // 表名
    protected $name = 'subject';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'number_people_text',
        'account_duration_text',
        'status_text'
    ];
    

    
    public function getNumberPeopleList()
    {
        return ['15人以下' => __('15人以下'), '15-30人' => __('15-30人'), '30-50人' => __('30-50人'), '50-100人' => __('50-100人'), '100人以上' => __('100人以上')];
    }

    public function getAccountDurationList()
    {
        return ['30分钟' => __('30分钟'), '1.5小时' => __('1.5小时'), '3小时' => __('3小时'), '6小时' => __('6小时'), '其他' => __('其他')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
    }


    public function getNumberPeopleTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['number_people']) ? $data['number_people'] : '');
        $list = $this->getNumberPeopleList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAccountDurationTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['account_duration']) ? $data['account_duration'] : '');
        $list = $this->getAccountDurationList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function admin()
    {
        return $this->belongsTo('app\admin\model\Admin', 'principal_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
